package com.atguigu.eduservice.controller;

import com.alibaba.excel.EasyExcel;
import com.atguigu.eduservice.entity.EduSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author cyt
 * @create 2020-05-06 21:28
 */

@Controller
public class ExcelWrite {
    @Autowired
    EduSubjectService eduSubjectService;


    @RequestMapping("/tt")
    @ResponseBody
    public String kk() {
        List<EduSubject> subjectList = eduSubjectService.list(null);
        // 写法1
        String fileName = "F:\\11.xlsx";
        // 这里 需要指定写用哪个class去写，然后写到第一个sheet，名字为模板 然后文件流会自动关闭
        // 如果这里想使用03 则 传入excelType参数即可
        EasyExcel.write(fileName, EduSubject.class).sheet("写入方法一").doWrite(subjectList);
        return "ok";
    }

}
